package de.pass.ch.junit;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.junit.Test;

import de.pass.ch.graph.SearchGraph;
import de.pass.ch.graph.UpdateableGraph;
import de.pass.ch.io.GraphIO;
import de.pass.ch.preprocessing.NodeOrder;
import de.pass.ch.preprocessing.WeightCalculation;
import de.pass.ch.pt.IStreetProfile;
import de.pass.ch.pt.StreetProfile;
import de.pass.ch.util.Constants;
import de.pass.ch.util.Util;

public class TestNodeOrder {

	public static final String DUMMY = "dummyGraph";
	public static final String LITAUEN = "D:\\CH\\litauen";
	public static final String DACH_DUR = "D:\\CH\\sparseDACH_dur";
	public static final String DACH = "D:\\CH\\sparseDACH";

	@Test
	public void testNodeOrder() {

		IStreetProfile streetProfile = StreetProfile
				.getInstance(StreetProfile.DEFAULT_PROFILE);
		UpdateableGraph graph = GraphIO.importUpdatableGraph(DACH, "",
				streetProfile, Constants.DISTANCE_OPT);

		System.out.println("#nodes: " + graph.noOfNodes());
		System.out.println("#edges: " + graph.noOfEdges());

		NodeOrder nodeOrder = new NodeOrder(new WeightCalculation(
				WeightCalculation.OWN_MODE), graph, null, null);

		nodeOrder.createHierarchy();

		int[] levels = graph.getLevelInformation();
		Util.serializeIntArray("D:\\CH\\nodeOrder_DACH_own2.ser", levels);

		SearchGraph sgr = new SearchGraph(graph);

		FileOutputStream fOut = null;

		try {

			fOut = new FileOutputStream("D:\\CH\\searchGraph.dach.own2.sgr");
			sgr.serializeFast(fOut);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			try {
				if (fOut != null)
					fOut.close();
			} catch (Exception e) {
			}
		}

	}

}
